package pta.MOOC.ch02.ex11;

import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        String x = scanner.nextLine();
        int n = Integer.parseInt(scanner.nextLine());
        int count = 0;
        int lineNumber = 0;
        while (true) {
            String line = scanner.nextLine();
            lineNumber++;
            if (line.equals("end")) {
                break;
            }
            if (line.contains(x)) {
                System.out.println((lineNumber + " " + line));
                count++;
                if (count == n) {
                    break;
                }
            }
        }
        System.out.println(count);
        scanner.close();
    }
}
